package com.duan.ad.listener;

import com.alibaba.fastjson.JSONObject;
import com.duan.ad.config.RabbitMaConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Component
public class AdListener {
    @Autowired
    private RestTemplate restTemplate;

    @RabbitListener(queues = RabbitMaConfig.AD_QUEUE)
    public void Message(Object message) {
        String s = restTemplate.getForObject("http://192.168.80.128/ad_load", String.class);
        System.out.println(s);
        Map map = JSONObject.parseObject(s, Map.class);
        if (!map.get("flag").toString().equals("true")) {
            throw  new RuntimeException();
        }
    }
}
